if (sessionStorage.getItem('gid') != null) {
	$.ajax({
		url: 'http://localhost:3000/admin/getGoodsById',
		method: 'GET',
		async: false,
		data: { id: sessionStorage.getItem('gid') },
		success: function (data) {
			var good = data.data;
			$('.gd')[0].innerHTML = `
     <div class="goodsimg">
     <div class="goodsbigimg">
       <img src="http://localhost:3000/file_upload/${good.cover}">
     </div>
   </div>
   <div class="goodscont">
     <div class="goodsname">${good.name}</div>
     <div class="goodsdis">${good.intro}</div>
     <div class="goodsnorms gattr">
       <span class="tit">规 格</span>
       <span style="cursor: pointer" class="gnorms norm-active">
         <i class="iconfont icon-xuanzhong3"></i>${good.spec}
       </span>
     </div>
     <div class="goodsnorms gattr">
       <span class="tit">库存</span>${good.stock}
     </div>
     <div class="goodsprices gattr">
       <span class="tit">价 格</span>
       <span class="opri">￥<span class="opcont" id="goodssprice">${good.price}</span></span>
     </div>

     <div class="goodsnum gattr">
       <span class="tit">数 量</span>
       <input type="button" id="gcut" class="btn" value="-" style="cursor: pointer" />
       <input type="text" name="goods_num" id="sum" disabled value="1" />
       <input type="button" id="gadd" class="btn" value="+" style="cursor: pointer" />
     </div>
     <div class="handle" style="border:none">
       <a href="javascript:void(0)">
         <p class="add" data-id="${good.id}">加入购物车</p>
       </a>
       <!-- <p class="buy">立即购买</p> -->
     </div>
   </div>
 </div>    
     `;
			// $('.typename')[0].innerHTML = good.typeName;
			// $('.gn')[0].innerHTML = good.name;
			$('.dateilsimg')[0].innerHTML = good.content;
			$('.nav-list')[0].innerHTML = `
      <a onclick="findGoodsByType(${good.typeId},'${good.typeName}')"><span class="typename" style="color:#ff852b;">${good.typeName}</span></a>
      <i class="iconfont icon-arrow-left"></i>
      <span class="gn">${good.name}</span>
      `;
			console.log(good.content);
		}
	});
}
$.ajax({
	url: 'http://localhost:3000/admin/hotList',
	method: 'GET',
	async: true,
	data: { page: 1, size: 2 },
	success: function (data) {
		$('.goodspage')[0].innerHTML = '';
		data.data.dataList.forEach(function (good, index) {
			$('.goodspage')[0].innerHTML += `
      <div class="goods">
      <a onclick="datai(${good.id})" href="javascript:void(0)"><img src="http://localhost:3000/update/${good.cover}" /></a>
      <p class="goodsprice">￥<span>${good.price}</span></p>
      <a onclick="datai(${good.id})" href="javascript:void(0)">
        <p class="goodsname">${good.name}</p>
      </a>
    </div>    
      `;
		});
	}
});

//数量增加或减少按钮功能实现
$('#gcut').on('click', function () {
	$('#sum').val() - 1;
	if ($('#sum').val() <= 1) {
		$('#sum').val(1);
	}
});
$('#gadd').on('click', function () {
	$('#sum').val() + 1;
});
$(document).on('click', '.add', function () {
	var goodId = $(this).attr('data-id');
	var index = layer.load();
	$.post('http://localhost:3000/admin/cartGoodAdd', { good_id: goodId, amount: $('#sum').val(), user_id: sessionStorage.getItem('userid') }, function (data) {
		layer.close(index);
		if (data.state === 1) {
			sessionStorage.removeItem('amount');
			layer.msg('加入成功', {
				icon: 1, // 成功图标
				time: 1200 //1.2秒关闭（如果不配置，默认是3秒）
			});
			cartn(); // 更新数量
		} else {
			layer.msg('操作失败', {
				icon: 2, // 失败图标
				time: 2000 //2秒关闭（如果不配置，默认是3秒）
			});
		}
	});
});
